package com.baosight.xCyber.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 吴起航
 */
@Component
public class EnvConfig {

    @Autowired
    private ApplicationContext context;

    public String getIHDBServer(){
        Environment env = context.getEnvironment();
        return env.getProperty("iHyperDB.server");
    }

    public String getDB2Server(){
        Environment env = context.getEnvironment();
        return env.getProperty("spring.datasource.url");
    }


    public String getTagTable(){
        Environment env = context.getEnvironment();
        return env.getProperty("xCyberTagTable");
    }


    public String getTreeTable(){
        Environment env = context.getEnvironment();
        return env.getProperty("xCyberTreeTable");
    }


    public String getMainTable(){
        Environment env = context.getEnvironment();
        return env.getProperty("xCyberMainTable");
    }


    public Map<String,Object> getExcelProperty(){
        int tagIndex = 2,zoneIndex = 6;
        boolean isZoneMore = false;
        Map<String,Object> excelPropertyMap = new HashMap<>();

        Environment env = context.getEnvironment();
        String temp = env.getProperty("tagIndex");
        if(temp!=null||!temp.equals("")){
            tagIndex = Integer.parseInt(temp);
        }
        excelPropertyMap.put("tagIndex",tagIndex);
        temp = env.getProperty("zoneIndex");
        if(temp!=null||!temp.equals("")){
            zoneIndex = Integer.parseInt(temp);
        }
        excelPropertyMap.put("zoneIndex",zoneIndex);
        temp = env.getProperty("isZoneMore");
        if(temp!=null||!temp.equals("")){
            isZoneMore = Boolean.parseBoolean(temp);
        }
        excelPropertyMap.put("isZoneMore",isZoneMore);
        return excelPropertyMap;
    }

    public RedisTemplate getRedisTemplate(){
        Environment env = context.getEnvironment();
        String redisCon = env.getProperty("spring.redis.host");
        if(redisCon!=null){
            return (RedisTemplate)context.getBean("redisTemplate");
        }
        return null;
    }


}
